﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using coliseu.BussinessLayer;

namespace coliseu.Views.Rotinas_Diarias
{
    public partial class FrmListReserva : Form
    {
        ReservaBL rBL = new ReservaBL();

        public FrmListReserva()
        {
            InitializeComponent();
        }

        private void FrmListReserva_Load(object sender, EventArgs e)
        {
            reservaBindingSource.DataSource = rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date);


            dtGrdVwBloco.DataSource = (from x in rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date)
                                       select new { x.area_lazer.descricao, x.data_utilizacao, x.hora_inicio, x.hora_fim, x.morador_apartamento.morador.nome }).ToList();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            reservaBindingSource.DataSource = rBL.selecionar(dateTimePicker1.Value.Date, dateTimePicker2.Value.Date);
            dtGrdVwBloco.DataSource = (from x in rBL.selecionar(dateTimePicker1.Value.Date, dateTimePicker2.Value.Date)
                                       select new { x.area_lazer.descricao, x.data_utilizacao, x.hora_inicio, x.hora_fim, x.morador_apartamento.morador.nome }).ToList();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (panel1.Visible)
                panel1.Visible = false;
            else
                panel1.Visible = true;
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Deseja excluir?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                rBL.excluir((reserva)reservaBindingSource.Current);
                reservaBindingSource.DataSource = rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date);
                dtGrdVwBloco.DataSource = (from x in rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date)
                                           select new { x.area_lazer.descricao, x.data_utilizacao, x.hora_inicio, x.hora_fim, x.morador_apartamento.morador.nome }).ToList();
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            FrmCadReserva c = new FrmCadReserva(((reserva)reservaBindingSource.Current), rBL);
            c.ShowDialog();
            reservaBindingSource.DataSource = rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date);
            dtGrdVwBloco.DataSource = (from x in rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date)
                                       select new { x.area_lazer.descricao, x.data_utilizacao, x.hora_inicio, x.hora_fim, x.morador_apartamento.morador.nome }).ToList();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            FrmCadReserva c = new FrmCadReserva(rBL);
            c.ShowDialog();
            reservaBindingSource.DataSource = rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date);
            dtGrdVwBloco.DataSource = (from x in rBL.selecionar(DateTime.Now.Date, DateTime.Now.Date)
                                       select new { x.area_lazer.descricao, x.data_utilizacao, x.hora_inicio, x.hora_fim, x.morador_apartamento.morador.nome }).ToList();
        }
    }
}
